import 'smart_device_info.dart';

// 房间卡片配置model
class RoomCardModel {
  int? id;
  int? roomId;
  String? name;
  int? deviceId;
  String? custom;
  int? type;
  int? order;
  DeviceInfoModel? deviceInfo;
  List<DeviceInfoModel>? relationDevices;

  RoomCardModel(
      {id,
      roomId,
      name,
      deviceId,
      custom,
      type,
      order,
      deviceInfo,
      relationDevices});

  RoomCardModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    roomId = json['room_id'];
    name = json['name'];
    deviceId = json['device_id'];
    custom = json['custom'];
    type = json['type'];
    order = json['order'];
    deviceInfo = json['device_info'] != null
        ? DeviceInfoModel.fromJson(json['device_info'])
        : null;
    if (json['relation_devices'] != null) {
      relationDevices = <DeviceInfoModel>[];
      json['relation_devices'].forEach((v) {
        relationDevices!.add(DeviceInfoModel.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['room_id'] = roomId;
    data['name'] = name;
    data['device_id'] = deviceId;
    data['custom'] = custom;
    data['type'] = type;
    data['order'] = order;
    if (deviceInfo != null) {
      data['device_info'] = deviceInfo!.toJson();
    }
    if (relationDevices != null) {
      data['relation_devices'] =
          relationDevices!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}
